using System.Collections.ObjectModel;
using HMCollada.Core;
using System.Xml;

namespace HMCollada.Core {
    internal struct HMColladaPH {
        internal int[] p;
        internal Collection<int[]> h;
    }
}

namespace HMCollada {
    internal partial class HMColladaLoader {
        private static HMColladaPH LoadPH() {
            HMColladaPH newPH = new HMColladaPH();
            newPH.h = new Collection<int[]>();

            string content;
            string[] values;

            if (!colladaReader.IsEmptyElement) colladaReader.Read();
            do {
                if (colladaReader.NodeType != XmlNodeType.EndElement) {
                    switch (colladaReader.Name) {
                        case "p":
                            content = ReadString().Trim();
                            while (content.Contains("  ")) content = content.Replace("  ", " ");
                            values = content.Split(new char[] { ' ' });
                            newPH.p = new int[values.Length];
                            for (int i = 0; i < newPH.p.Length; i++) newPH.p[i] = int.Parse(values[i]);
                            break;

                        case "h":
                            content = ReadString().Trim();
                            while (content.Contains("  ")) content = content.Replace("  ", " ");
                            values = content.Split(new char[] { ' ' });
                            int[] h = new int[values.Length];
                            for (int i = 0; i < h.Length; i++) h[i] = int.Parse(values[i]);
                            newPH.h.Add(h);
                            break;
                    }
                }

                if (!colladaReader.IsEmptyElement) colladaReader.Read();
            } while (colladaReader.Name != "ph");
            
            if (colladaReader.IsEmptyElement) colladaReader.Read();
            return newPH;
        }
    }
}